import 'package:flutter/material.dart';
import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
import 'package:hbtrans_flutter/beans/news_bean.dart';
import 'package:hbtrans_flutter/utils/mydio.dart';

import '../../apis.dart';
import '../../const.dart';

class ArticleDetail extends StatefulWidget {
  final articleId;

  const ArticleDetail({Key key, this.articleId}) : super(key: key);

  @override
  _ArticleDetailState createState() => _ArticleDetailState();
}

class _ArticleDetailState extends State<ArticleDetail> {
  var loadingDialog;
  var content = '';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Color(0xff23AFDC),
        elevation: 0.0,
      ),
      body: Padding(
        padding: const EdgeInsets.all(10.0),
        child: SingleChildScrollView(
          child: HtmlWidget(
            content,
            webView: true,
          ),
        ),
      ),
    );
  }

  @override
  void initState() {
    super.initState();
    _getArticle();
  }

  _getArticle() {
    Map data = new Map<String, dynamic>();
    data["articleId"] = widget.articleId;
    MyDio.getInstance(url: Const.TRANS_SERVER_MY_PATH).get(Apis.articleInfo,
            (data) {
          if (loadingDialog != null) {
            loadingDialog = null;
            Navigator.pop(context);
          }
          NewsBean newsBean = NewsBean.fromJson(data);
          setState(() {
            content = newsBean.content;
          });
        }, params: data);
  }
}
